package leetcode.每日一题;

import org.junit.Test;

import java.lang.reflect.Array;
import java.util.*;

/**
 * @author ：zsy
 * @date ：Created 2022/9/22 10:42 AM
 * @description：https://leetcode.cn/problems/check-array-formation-through-concatenation/
 */
public class 能否连接形成数组 {
    @Test
    public void test() {
        Solution solution = new Solution();
    }

    class Solution {
        public boolean canFormArray(int[] arr, int[][] pieces) {
            Map<Integer, Integer> map = new HashMap<>();
            for (int i = 0; i < pieces.length; i++) {
                map.put(pieces[i][0], i);
            }
            for (int i = 0; i < arr.length;) {
                if (!map.containsKey(arr[i])) return false;
                Integer idx = map.get(arr[i]);
                int len = pieces[idx].length;
                for (int j = 0; j < len; j++) {
                    if (arr[i + j] != pieces[idx][j]) {
                        return false;
                    }
                }
                i += len;
            }
            return true;
        }
    }



}
